package com.jooink.experiments.elementalgetusermedia.client;

import com.jooink.experiments.elementalgetusermedia.client.ElementalUtils.UserMediaCallback;



//keeps the url of the usermedia to avoid unecessary 'getUserMedia' requests

public class UserMediaHolder {
	private boolean userMediaAvailable = false;
	private String userMediaUrl;
	
	
	
	
	public boolean getUserMedia(final UserMediaCallback userMediaCallback) {
		
		if(!userMediaAvailable) {
			boolean hasUserMedia = ElementalUtils.getUserVideo( new UserMediaCallback() {
				
				@Override
				public void onSuccess(String url) {
					userMediaAvailable = true;
					userMediaUrl = url;
					userMediaCallback.onSuccess(url);
				}
				
				@Override
				public void onFail() {
					userMediaAvailable = false;
					userMediaCallback.onFail();
				}
			});
			return hasUserMedia;
		} else {
			userMediaCallback.onSuccess(userMediaUrl);
			return true;
		}
		
	}

	


}
